package com.cyw.system.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cyw.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Random;

/**
 * 标签对象 tb_label
 *
 * @author myproject
 * @date 2022-11-22
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("tb_label")
public class TbLabel extends BaseEntity {

  private static final long serialVersionUID = 1L;

  /** */
  @TableId(value = "id")
  private Long id;
  /** 标签名 */
  private String labelName;
  /** 颜色 */
  private String color;

  /** 随机颜色 */
  @TableField(exist = false)
  private String randomColor = "#" + random();

  private static String random() {

    String r, g, b;
    Random random = new Random();
    r = Integer.toHexString(random.nextInt(256)).toUpperCase();
    g = Integer.toHexString(random.nextInt(256)).toUpperCase();
    b = Integer.toHexString(random.nextInt(256)).toUpperCase();
    r = r.length() == 1 ? "0" + r : r;
    g = g.length() == 1 ? "0" + g : g;
    b = b.length() == 1 ? "0" + b : b;

    return r + g + b;
  }
}
